<?php
// $Id: index.php,v 1.11 2004/12/02 C. Felix AKA the Cat
//  ------------------------------------------------------------------------ //
//             XF Guestbook                                                  //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

include("../../mainfile.php");
include_once("include/functions.php");

$xoopsOption['template_main'] = 'xfguestbook_index.html';
include_once(XOOPS_ROOT_PATH."/header.php");
include_once(XOOPS_ROOT_PATH."/class/pagenav.php");
include_once XOOPS_ROOT_PATH."/class/xoopslists.php";
include_once(XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/class/msg.php");

$msg_handler =& xoops_getmodulehandler('msg');

foreach ( $_GET as $k => $v ) { ${$k} = $v; }
if (!isset($op)) $op = 'show_all'; 
if (!isset($debut)) $debut=0;

$criteria = new Criteria('moderate', 0);
$nbmsg = $msg_handler->getCount($criteria);

$xoopsTpl->assign('msg_message_count', sprintf(_MD_XFGB_THEREIS, "<b>".$nbmsg."</b>"));
$xoopsTpl->assign('msg_moderated',$xoopsModuleConfig['moderate']);

$nb_perpage =  $xoopsModuleConfig['perpage'];	

//Admin or not
($xoopsUser) ? $adminview=$xoopsUser->isAdmin() :$adminview=0;

if ($adminview) {
	$nbwait = $msg_handler->getCount(new Criteria('moderate', '1'));
	$xoopsTpl->assign('msg_moderate_text', sprintf(_MD_XFGB_MODERATING,"<font class='fg2'><a href='index.php?op=show_waiting'>".$nbwait."</a></font>"));
}


switch ($op) {
    case "show_waiting":
		$pagenav = new XoopsPageNav($nbwait, $nb_perpage, $debut, "debut", "op=show_waiting");
		$xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
		$criteria = new Criteria('moderate', 1);
		$criteria->setOrder('DESC');
		$criteria->setLimit($nb_perpage);
		$criteria->setStart($debut);
		$msg =& $msg_handler->getObjects($criteria);
		$nbwait-=$debut;
		$nbmsg = $nbwait;
		xfgb_getmsg($msg);
    break;
	
    case "show_one":
		if ($adminview) {
			$criteria = new Criteria('msg_id', $id);
		} else {
			$criteria = new CriteriaCompo(new Criteria('moderate', '0'));
			$criteria->add(new Criteria('msg_id', $id));
		}
		$msg =& $msg_handler->getObjects($criteria);
		xfgb_getmsg($msg);
	break;
	
    case "show_country":
		$criteria = new CriteriaCompo(new Criteria('moderate', '0'));
		$criteria->add(new Criteria('country', $param));
		$nbmsg = $msg_handler->getCount($criteria);
		$pagenav = new XoopsPageNav($nbmsg, $nb_perpage, $debut, "debut", "op=show_country&param=".$param);
		$criteria->setOrder('DESC');
		$criteria->setLimit($nb_perpage);
		$criteria->setStart($debut);
		$msg =& $msg_handler->getObjects($criteria);
		$nbmsg-=$debut;
		$xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
		xfgb_getmsg($msg);
	break;

    case "show_gender":
		$criteria = new CriteriaCompo(new Criteria('moderate', '0'));
		$criteria->add(new Criteria('gender', $param));
		$nbmsg = $msg_handler->getCount($criteria);
		$pagenav = new XoopsPageNav($nbmsg, $nb_perpage, $debut, "debut", "op=show_gender&param=".$param);
		$criteria->setOrder('DESC');
		$criteria->setLimit($nb_perpage);
		$criteria->setStart($debut);
		$msg =& $msg_handler->getObjects($criteria);
		$nbmsg-=$debut;
		$xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
		xfgb_getmsg($msg);
	break;

   case "show_all":
    default:
		$pagenav = new XoopsPageNav($nbmsg, $nb_perpage, $debut, "debut", "");
		$xoopsTpl->assign('msg_page_nav', $pagenav->renderNav());
		$criteria = new Criteria('moderate', 0);
		$criteria->setOrder('DESC');
		$criteria->setLimit($nb_perpage);
		$criteria->setStart($debut);
		$msg =& $msg_handler->getObjects($criteria);
		$nbmsg-=$debut;
		xfgb_getmsg($msg);
	break;

}

xfgb_copyright();

include(XOOPS_ROOT_PATH."/footer.php");
?>